package com.hkyl.hospital.web.controller;

import com.github.pagehelper.PageInfo;
import com.hkyl.hospital.domain.ResultVo;
import com.hkyl.hospital.entity.HospitalApply;
import com.hkyl.hospital.service.HospitalApplysService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author sjh
 * @date 2023/07/13 14:26:15
 */
@RestController
@RequestMapping("hospital")
public class HospitalApplysController {

    Logger logger = LoggerFactory.getLogger(HospitalApplysController.class);
    @Autowired
    private HospitalApplysService hospitalApplysService;

    @PostMapping("select")
    public ResultVo select(@RequestBody Map map) {
        logger.info(map.toString());
        Integer pageNumber = (Integer) map.get("pageNumber");
        Integer pageSize = (Integer) map.get("pageSize");
        PageInfo<HospitalApply> hospitalApplies = new PageInfo<>(hospitalApplysService.select(pageNumber, pageSize));
        return ResultVo.success(hospitalApplies);
    }

    @PostMapping("change")
    public ResultVo change(@RequestBody String applyId ) {
        logger.info("+++++++++++++++++++++++++++");
        int rows = hospitalApplysService.changeStatus(Integer.valueOf(applyId));
        return rows > 0 ? ResultVo.success() : ResultVo.failure("");
    }

    @PostMapping("applyHospital")
    public ResultVo applyHospital(@RequestBody HospitalApply hospitalApply) {
        return ResultVo.success("提交成功",hospitalApplysService.applyHospital(hospitalApply));
    }

    @PostMapping("updateApply")
    public ResultVo updateApply(@RequestBody HospitalApply hospitalApply) {
        return ResultVo.success("编辑成功",hospitalApplysService.updateApply(hospitalApply));
    }

}
